#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e4+10,MAXM=1e5+10,INF=0x3f3f3f3f;
int n,m,k,fa[MAXN],cnt,ans[MAXM],sum[2];
bool mark[MAXM];
struct edge
{
	int u,v,typ;
}e[MAXM*2];
int getfa(int x)
{
	return fa[x]=x==fa[x]?x:getfa(fa[x]);
}
void MST(bool typ,int _max)
{
	for(int i=1;i<=m;++i)
	{
		if(!(e[i].typ^typ)&&sum[typ]<_max)
		{
			int a=getfa(e[i].u),b=getfa(e[i].v);
			if(a==b)continue;
			fa[a]=b;
			ans[++cnt]=i;
			mark[i]=true;
			++sum[typ];
		}
	}
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=m;++i)scanf("%d%d%d",&e[i].u,&e[i].v,&e[i].typ);
	for(int i=1;i<=n;++i)fa[i]=i;
	MST(1,INF);
	MST(0,INF);
	if(sum[0]+sum[1]!=n-1||sum[0]>k)
	{
		printf("no solution\n");
		return 0;
	}
	cnt=0;
	sum[0]=sum[1]=0;
	for(int i=1;i<=n;++i)fa[i]=i;
	for(int i=1;i<=m;++i)
	{
		if(e[i].typ==0&&mark[i])
		{
			int a=getfa(e[i].u),b=getfa(e[i].v);
			if(a==b)continue;
			fa[a]=b;
			++sum[0];
			ans[++cnt]=i;
		}
	}
	MST(0,k);
	MST(1,INF);
	if(sum[0]<k)
	{
		printf("no solution\n");
		return 0;
	}
	for(int i=1;i<=cnt;++i)printf("%d %d %d\n",e[ans[i]].u,e[ans[i]].v,e[ans[i]].typ);
	return 0;
}
